package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");

		// response.setCharacterEncoding("utf-8");

		//request.setCharacterEncoding("utf-8");

		String username = request.getParameter("username");

		System.out.println(username);
		String password = request.getParameter("password");
		System.out.println(password);
		response.getWriter().append("username:" + username).append("\npassword:" + password + "<br>").append("age:");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");

		// response.setCharacterEncoding("utf-8");

		request.setCharacterEncoding("utf-8");

		String username = request.getParameter("username");

		System.out.println(username);
		String password = request.getParameter("password");
		System.out.println(password);
		
		
		StringBuilder sb = new StringBuilder("<!DOCTYPE html>\n")
				.append("<html>\n")
				.append("<head>\n")
				.append("<meta charset=\"UTF-8\">\n")
				.append("</head>\n")
				.append("<body>\n")
				.append("username:"+username+"\n<br>")
				.append("password:"+password+"\n")
				.append("</body>\n")
				.append("</html>")
				;
		
		response.getWriter().append(sb.toString());
	}

}
